package cn.zhku.edu.userservice.controller;

import cn.zhku.edu.feign.common.R;
import cn.zhku.edu.feign.pojo.entry.User;
import cn.zhku.edu.userservice.service.UserServies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author clk
 */

@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserServies userServies;

    @RequestMapping(value = "/test")
    public R test(@RequestParam String uid){

        return new R(200,"访问成功！",userServies.selectByPrimaryKey(uid));
    }
    @RequestMapping("/updateByPrimaryKey")
    public R updateByPrimaryKey(@RequestParam String uid, @RequestParam String username, @RequestParam String password, @RequestParam String avatar,@RequestParam String phone,@RequestParam String sex,@RequestParam String address1,@RequestParam String address11,@RequestParam String address2,@RequestParam String address21){
        User user = new User();
        user.setUid(uid);
        user.setPassword(password);
        user.setUsername(username);
        user.setAvatar(avatar);
        user.setAddress1(address1);
        user.setAddress11(address11);
        user.setAddress2(address2);
        user.setAddress21(address21);
        user.setPhone(phone);
        user.setSex(sex);

        return new R(200,avatar,userServies.updateByPrimaryKeySelective(user));
    }
    @PostMapping("/login")
    public R login(User user){
        return userServies.login(user);
    }

    @PostMapping("/register")
    public String register(User user){
        return userServies.regist(user);
    }
}
